package com.ttpai.boot.lbs.dao;

import java.util.List;

import com.ttpai.boot.lbs.model.BossInvitationVO;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;

@DAO
public interface BossInvitationDAO {

    String TABLE_NAME = " _KAIL_BOSS_INVITATION ";
    String ALL_FIELD = " AUCTION_ID,INVITATION_TIME,CHECK_TIME,CHECK_ADMIN_NAME,CITY_NAME,AREA_NAME,ADDRESS,LNG,LAT,HAND_FIX ";
    String ALL_PROP = " :vo.auctionId,:vo.invitationTime,:vo.checkTime,:vo.checkAdminName,:vo.cityName,:vo.areaName,:vo.address,:vo.lng,:vo.lat ";

    String ORDER_BY_INVITATION_TIME = " ORDER BY INVITATION_TIME ";

    @SQL("SELECT " + ALL_FIELD + " FROM " + TABLE_NAME + " WHERE 1=1" +
            " #if(null!=:p.auctionId && ''!=:p.auctionId){ AND AUCTION_ID=:p.auctionId }" +
            " #if(null!=:p.cityName && ''!=:p.cityName){ AND CITY_NAME=:p.cityName }" +
            " #if(null!=:p.checkTime && ''!=:p.checkTime){ AND DATE(CHECK_TIME)=DATE(:p.checkTime)}" +
            ORDER_BY_INVITATION_TIME)
    List<BossInvitationVO> select(@SQLParam("p") BossInvitationVO p);

    @SQL("SELECT " + ALL_FIELD + " FROM " + TABLE_NAME + " WHERE AUCTION_ID=:auctionId ")
    List<BossInvitationVO> selectOne(@SQLParam("id") Integer auctionId);

    @SQL("SELECT CITY_NAME FROM " + TABLE_NAME + " GROUP BY CITY_NAME")
    List<String> selectAllCity();

    @SQL("SELECT DATE(CHECK_TIME) FROM " + TABLE_NAME + " WHERE CITY_NAME=:cityName AND HAND_FIX =1  GROUP BY DATE(CHECK_TIME)")
    List<String> selectAllCheckTime(@SQLParam("cityName") String cityName);


    @SQL("INSERT INTO " + TABLE_NAME + " (" + ALL_FIELD + ") VALUES (" + ALL_PROP + ")")
    Integer insert(@SQLParam("vo") BossInvitationVO metroPoint);

    @SQL("UPDATE " + TABLE_NAME + " SET " +
            " #if(null != :mp.lng){ LNG=:mp.lng, } " +
            " #if(null != :mp.lat){ LAT=:mp.lat, } " +
            " #if(null != :mp.handFix){ HAND_FIX=:mp.handFix, } " +
            " AUCTION_ID=AUCTION_ID " +
            " WHERE AUCTION_ID=:mp.auctionId")
	Integer update(@SQLParam("mp") BossInvitationVO metroPoint);

}
